package bishi.tengxun;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/08/22 20:44
 */
public class two {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        int p = 1000000007;
        while(T>0){
            int n = in.nextInt();
            int[] nums = new int[n];
            int index = 0;
            while (index<n) {// 注意，如果输入是多个测试用例，请通过while循环处理多个测试用例
                nums[index++] = in.nextInt();
            }
            int res = 0;
            Arrays.sort(nums);
            int pq = 0;
            for(int i=nums.length-1;i>=0;i--){
                res = (res+(nums[i]+pq)%p)%p;
                pq = (pq*2+nums[i])%p;
            }
            System.out.println(res);
            T--;
        }
    }
}
